TARGET = svdTester
CXX = g++

all: $(TARGET).deb $(TARGET).opt
	./$(TARGET).deb

run: $(TARGET).deb
	./$(TARGET).deb

#ALLFLAGS     = -Wall -Wstrict-aliasing -Wextra -g -pthread -I/opt/intel/composer_xe_2013_sp1.0.080/mkl/include/
ALLFLAGS     = -Wall -Wstrict-aliasing -Wextra -g -pthread 
RELEASEFLAGS = -DNDEBUG -fPIC -Os -fstrict-aliasing -O3
DEBUGFLAGS   = -O0
# OPENMPFLAGS  = -fopenmp
#LIBLAPACK= -L/usr/lib/lapack/ -llapack
#LIBLAPACK= -L./lapack-3.4.2/ -llapack
LIBLAPACK= -llapack
LIBMRRR= -L../mr3smp-20130228/LIB -lmrrr
LIBBLAS= -lblas
#LIBBLAS= -L/home/mrdaka/Documents/Master/Thesis/code/OpenBLAS -lopenblas
#LIBBLAS= -L/opt/intel/composer_xe_2013_sp1.0.080/mkl/lib/ia32/ -lmkl_intel -lmkl_core -lmkl_gnu_thread -fopenmp

LIBS = -lrt $(LIBBLAS) $(LIBLAPACK) $(LIBMRRR) -lgfortran -lm -lgcc_s 

INCLUDES = $(wildcard *.h)
SOURCES = $(wildcard *.cpp)
OPTIMIZEDOBJECTS = $(SOURCES:.cpp=_opt.o) 
DEBUGOBJECTS = $(SOURCES:.cpp=_deb.o) 

ifeq ($(wildcard .depend), .depend)
include .depend
endif


$(TARGET).opt: $(OPTIMIZEDOBJECTS) Makefile
	$(CXX) $(ALLFLAGS) $(RELEASEFLAGS) -flto $(OPTIMIZEDOBJECTS) ${LIBS} -o $@

$(TARGET).deb: $(DEBUGOBJECTS) Makefile 
	$(CXX) $(ALLFLAGS) $(DEBUGFLAGS) $(DEBUGOBJECTS)  ${LIBS} -o $@

#%_opt.o : %.cpp %.h Makefile
#	$(CXX) $(ALLFLAGS) $(RELEASEFLAGS) -c $< -o $@

#%_deb.o : %.cpp %.h Makefile
#	$(CXX) $(ALLFLAGS) $(DEBUGFLAGS) -c $< -o $@



clean: clear
clear:
	rm -f *.o $(TARGET) $(TARGET).* 

profile: openmp
#	valgrind --tool=helgrind ./$(TARGET)
	valgrind --tool=callgrind --dump-instr=yes --simulate-cache=yes --collect-jumps=yes ./$(TARGET)
check: $(TARGET).deb 
	valgrind --leak-check=full --show-reachable=no --malloc-fill=CF --track-origins=yes ./$(TARGET).deb --alltests

depend:
	$(CXX) -MM $(SOURCES) >.tmp
	cat .tmp | sed "s/\.o/_deb.o/g" | sed "s/h$$/h Makefile\n\t$$\(CXX\) $$\(ALLFLAGS\) $$\(DEBUGFLAGS\) -c $$< -o $$\@/" > .depend
	cat .tmp | sed "s/\.o/_opt.o/g" | sed "s/h$$/h Makefile\n\t$$\(CXX\) $$\(ALLFLAGS\) $$\(RELEASEFLAGS\) -c $$< -o $$\@/">> .depend
	rm .tmp

